package com.pets.springboot_petshop.mapper;

import com.pets.springboot_petshop.entity.Petknowledge;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 下午4:39 周二
 * @Description: 宣传栏访问层接口
 */
@Mapper
@Repository
public interface PetknowledgeMapper {
    //id查询
    @Select("SELECT " +
            "a.id, " +
            "a.title, " +
            "b.username, " +
            "a.content, " +
            "a.admin_id, " +
            "a.create_time " +
            "FROM `petknowledge` a " +
            "JOIN admin b ON a.admin_id = b.id " +
            "WHERE a.id = #{id}")
    Petknowledge select(int id);
    //admin_id查询
    @Select("SELECT " +
            "a.id, " +
            "a.title, " +
            "b.username, " +
            "a.content, " +
            "a.admin_id, " +
            "a.create_time " +
            "FROM `petknowledge` a " +
            "JOIN admin b ON a.admin_id = b.id " +
            "WHERE a.admin_id = #{admin_id}")
    List<Petknowledge> selectadmin_id(int admin_id);
    //查询所有
    @Select("SELECT " +
            "a.id, " +
            "a.title, " +
            "b.username, " +
            "a.content, " +
            "a.admin_id, " +
            "a.create_time " +
            "FROM `petknowledge` a " +
            "JOIN admin b ON a.admin_id = b.id ")
    List<Petknowledge> findAll();
    //添加
    @Insert("insert into `petknowledge`(title,content,admin_id,create_time,update_time)values(#{title},#{content},#{admin_id},now(),now());")
    int add(Petknowledge petknowledge);
    //删除
    @Delete("delete from `petknowledge` where id=#{id};")
    int delete(int id);
    //修改数据
    @Update("UPDATE `petknowledge` SET title=#{title},content=#{content},admin_id=#{admin_id},update_time=now() where id= #{id};")
    int update(Petknowledge petknowledge);
}
